package com.zzzy.doc.controller.mydoc;


import com.zzzy.common.vo.AjaxResult;
import com.zzzy.doc.service.mydoc.MyDocAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Tag(name = "我的公文-审核修订", description = "doc111")
@Validated
@RestController
@RequestMapping("/doc/my")
public class MyDocAuditController {

    @Resource
    private MyDocAuditService myDocAuditService;

    @PutMapping("/applyAudit")
    @Operation(summary = "申请审核修订")
    @Parameter(name = "id", description = "公文ID", required = true)
    @Parameter(name = "userId", description = "用户ID", required = true)
    @PreAuthorize("@pvs.hasPermission('doc:my:update')")
    public AjaxResult applyAudit(@NotNull(message = "公文ID不能为空") Long id, @NotNull(message = "用户ID不能为空") Long userId) {
        myDocAuditService.applyAudit(id, userId);
        return AjaxResult.success();
    }

    @PutMapping("/auditComplete/{id}")
    @Operation(summary = "审核修订完毕进入会签")
    @Parameter(name = "id", description = "公文ID", required = true)
    @PreAuthorize("@pvs.hasPermission('doc:my:update')")
    public AjaxResult auditComplete(@NotNull(message = "公文ID不能为空") @PathVariable("id") Long id) {
        myDocAuditService.auditComplete(id);
        return AjaxResult.success();
    }

}
